<?php
$tocken 		= Zendvn_Form_Tocken::tocken($this->cmsUrl());

$urlCaptch		= $this->cmsUrl(array(
									'module' 		=> $this->arrParam['module'],
									'controller' 	=> $this->arrParam['controller'],
									'action' 		=> 'captcha-image'
									));
?>
<script type="text/javascript">
$(document).ready(function() {
	
	$(".bg_error").hover(function(){
		$(this).next('.note_error').fadeIn(100);
	},function(){
		$(this).next('.note_error').fadeOut(500);
	});
	
	$('#appForm .btn2').click(function(){
		addTocken('<?php echo $tocken; ?>');
		$('.bg_error').unbind('mouseenter mouseleave');
		$('.bg_error').removeClass('bg_error');
		$('.note_error').html('');
		$('#appForm').ajaxSubmit({dataType: "json", success: optionsEnt});
		return false;
	});
	function optionsEnt(data){
		if(data.type == 'success'){
			//$('#cboxClose').click();
		}else{	
			for(var x in data.msg){
				$('#'+x).addClass('bg_error');
				loadError($('#'+x),data.msg[x]);
			}	
		}
	}
	
});
function addInput(theForm, type, key, value){
	//theForm.removeChild(key);
	var input 	= document.createElement('input');
	input.type 	= type;
	input.name 	= key;
	input.value = value;
	theForm.appendChild(input);
}
function getData(data){
	$('div.captcha-image').html(data);
	return false;
}
$('.refresh').click(function(e){
	e.preventDefault();
	refreshCaptcha();
});
function loadError(selector, value) {
	var html = selector.parent().find('.note_error').html();
	selector.parent().find('.note_error').html(value + '<span class="decor"></span>');
	selector.hover(function() {
		selector.parent().find('.note_error').slideDown(150);
	}, function() {
		selector.parent().find('.note_error').slideUp(150);
	});
}
function refreshCaptcha(){
	var captchaID = $("#captchaID").val();
	$.get('<?php echo $urlCaptch . '/captchaID/';?>'+captchaID,getData);
}
function addTocken(tocken){
	var theForm = document.forms['appForm'];
	addInput(theForm, 'hidden', 'tocken', tocken);
}
</script>